#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
const int maxn = 200+10;
int F[maxn];

void init(int n) {
    for (int i = 1; i <= n; i++) {
        F[i] = i;
    }
}

bool is_root(int x) {
    return F[x] == x;
}

int find(int x) {
    if (is_root(x))return x;
    return F[x] = find(F[x]);
}

bool merge(int x, int y) {
    int fx = find(x), fy = find(y);
    if (fx == fy)return false;
    F[fx] = fy;
    return true;
}

int count(int n) {
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (F[i] == i)++cnt;
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0)break;

        init(n);

        while (m--) {
            int x, y;
            cin >> x >> y;
            merge(x, y);

        }
        cout << count(n) - 1 << endl;
    }
    return 0;
}